import { Provide } from '@midwayjs/decorator';
import { InjectEntityModel } from '@midwayjs/orm';
import { Repository } from 'typeorm';
import { CreateRole, UpdateRoleDto } from '../../../dto/admin/sys/userRole';
import { SysRole } from '../../../entity/admin/sys/role';
import { BaseService } from '../../baseService';

@Provide()
export class SysRoleServiec extends BaseService {
  @InjectEntityModel(SysRole)
  sysRole: Repository<SysRole>;

  async getRoleList() {
    const list = await this.sysRole.find();
    return list;
  }

  async createRole(role: CreateRole) {
    const data = await this.sysRole.save(role);
    return data;
  }

  async updateRole(role: UpdateRoleDto) {
    const data = await this.sysRole.save(role);
    return data;
  }

  async getRoleById(id: number) {
    const role = this.sysRole.findOne(id);
    return role;
  }
}
